package neuralNetwork;

import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.util.Arrays;

import beerAgent.BeerParameters;
import evolutionaryLoop.EvolutionaryParameters;
import evolutionaryLoop.selectionMechanisme.SigmaSelection;
import evolutionaryLoop.selectionProtocol.OverProduction;
import evolutionaryProblems.Problem;
import genotype.BeerGenotype;

public class CTRNNTest {

	public static void main(String[] args) {
//		int[] nofNeuronsPerLayer = {3,2,6,1};
//		EvolutionaryParameters parameters = initialise(null); 
//		BeerGenotype genotype = new BeerGenotype(nofNeuronsPerLayer, parameters);
//		CTRNN ctrnn = new CTRNN(nofNeuronsPerLayer); 
//		ctrnn.setWeights(convertfuck(genotype.getArrayGenotype())); 
//		System.out.println(ctrnn);
		test(); 
	}
	
	public static double[] convertfuck(Double[] array){
		double[] newArray = new double[array.length]; 
		for (int i = 0; i < array.length; i++) {
			newArray[i] = array[i]; 
		}
		return newArray; 
	}
	
	
	public static EvolutionaryParameters initialise(Problem problem) {
		BeerParameters parameters = new BeerParameters();
		int[] nofNeuronsPerLayer = {3,2,6,1};
		
		parameters.setMaxNumberOfIterations(1000); 
		parameters.setMutationRate(0.05); 
		parameters.setCrossoverRate(0.9); 
		parameters.setNumOfChildenToBeGenerated(100); 
		parameters.setPopulationSize(100); 
		parameters.setElitims(1);
		parameters.setViewMap(false);
		parameters.setTimePerFrame(500);
		parameters.setNetworkLayout(nofNeuronsPerLayer);
		parameters.setCulling(0);
		parameters.setCrossoverPoints(1); 
		parameters.setAdultSelectionProtocol(new OverProduction(parameters)); 
		parameters.setParenetSelectionMechanism(new SigmaSelection()); 
		parameters.setMinGain(1.0);
		parameters.setMaxGain(1.0);
		parameters.setMinTimeCons(2.0);
		parameters.setMaxTimeCons(2.0);
		parameters.setMinBias(3.0);
		parameters.setMaxBias(3.0);
		parameters.setMinWeight(5.0);
		parameters.setMaxWeight(5.0);
		
		FileSystem fileSys = FileSystems.getDefault();
		String sep = fileSys.getSeparator();
		parameters.setWriteStatistics("OneMax" + sep + "Project1-Task3" + sep + "OneMax ");
		return parameters; 
	}
	
	public static void test(){
		int[] neuronsPerLayer = {5,2,2}; 
		double[] testWeights = {1,1,1,1, 1.5,2,1,1.5, -5,0,-2,-8,    4,-4, 3,2, -2,-1, 4,4, 0,2,  -1,5,-3,-5,  1,2,0,-3,  4,3,  -2,4}; 
		boolean[] testSensors = {false,false,true,true,false}; 
		CTRNN ctrnn = new CTRNN(neuronsPerLayer); 
		ctrnn.setWeights(testWeights); 
		
		System.out.println(ctrnn);
		System.out.println();
		
		System.out.println(ctrnn.activationString());
		System.out.println();
		
		System.out.println(Arrays.toString(ctrnn.update(testSensors))); 
		System.out.println(ctrnn.activationString());
		System.out.println();
		
		System.out.println(Arrays.toString(ctrnn.update(testSensors))); 
		System.out.println(ctrnn.activationString());
		System.out.println();
		
		
	}
		
}
